# collections
from collections import namedtuple, deque, Counter
import base64
Point = namedtuple("Point", ["x", "y"])
p = Point(1, 2)
print(p.x, p.y) # 1 2
print(isinstance(p, tuple), isinstance(p, Point)) # True True

q = deque(["a", "b", "c"])
q.append("d")
q.appendleft("1")
print(q) # deque(['1', 'a', 'b', 'c', 'd'])

c = Counter()
for ch in "I love you, liulin.":
    c[ch] = c[ch] + 1
print(c)

# base64的使用
encode = base64.encodebytes("中国".encode("utf-8")) # b'5Lit5Zu9\n'
print(encode)
decode = base64.decodebytes(b'5Lit5Zu9\n')
print(str(decode, encoding="utf-8")) # 中国

# struct：处理字节的数据类型
import struct
s1 = struct.pack(">I", 10240099)
print(s1) # b'\x00\x9c@c'

s2 = struct.unpack(">I", b'\x00\x9c@c')
print(s2) # (10240099,)

# 加密算法
import hashlib
md5 = hashlib.md5()
md5.update('how to use md5 in '.encode('utf-8'))
md5.update('python hashlib?'.encode('utf-8'))
print(md5.hexdigest()) # d26a53750bc40b38b65a520292f69306

sha1 = hashlib.sha1()
sha1.update('how to use sha1 in '.encode('utf-8'))
sha1.update('python hashlib?'.encode('utf-8'))
print(sha1.hexdigest()) # 2c76b57293ce30acef38d98f6046927161b46a44








